package com.spring.boot.quartz.controller;

import com.constant.entity.Result;
import com.spring.boot.quartz.service.EncapsulationQuartzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.custom.spring.boot.useless.QuartzJob;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 定时任务网络接口
 *
 * @author LiKun
 * @date 2021/7/30 17:01
 */
@RestController
@RequestMapping("/quartz")
@Api(tags = "Quartz-定时任务模块")
public class QuartzController {
    @Resource
    private EncapsulationQuartzService encapsulationQuartzService;

    @PutMapping("/add")
    @ApiOperation(value = "定时任务添加接口", notes = "添加启动定时任务")
    public Result<String> addJob(@RequestBody QuartzJob quartzJob) throws SchedulerException {
        encapsulationQuartzService.addJob(quartzJob);
        return Result.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "定时任务删除接口", notes = "删除指定的定时任务")
    public Result<String> deleteJob(@RequestBody QuartzJob quartzJob) throws SchedulerException {
        encapsulationQuartzService.deleteJob(quartzJob);
        return Result.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "定时任务修改接口", notes = "修改指定的定时任务")
    public Result<String> updateJob(@RequestBody QuartzJob quartzJob) throws SchedulerException {
        encapsulationQuartzService.updateJob(quartzJob);
        return Result.success();
    }
}
